package com.example.smartclassroom.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.smartclassroom.entity.form.LoginForm;
import com.example.smartclassroom.entity.Student;
import com.example.smartclassroom.mapper.StudentMapper;
import com.example.smartclassroom.service.StudentService;
import com.example.smartclassroom.util.JsonDate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class StudentSeiveceImpl extends ServiceImpl<StudentMapper, Student> implements StudentService{
    @Autowired
    private StudentMapper studentMapper;
    //学生登录
    public Student login(LoginForm loginForm) {
        Student login = studentMapper.login(loginForm);
        if(login!=null){
            return login;
        }
        throw  new RuntimeException("用户名或密码错误");
    }

    //学生注册
    public Integer register(LoginForm loginForm) {
        return studentMapper.insert(loginForm);
    }

    //编辑学生信息
    public JsonDate update(Student student) {
        JsonDate date = new JsonDate();
        Integer rows=studentMapper.update(student);
        if (rows>0){
            date.setCode(0);
            date.setMsg("success");
        }else {
            date.setCode(1);
            date.setMsg("fail");
        }
        return date;
    }
}
